<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      方法①：双重for循环
      方法②：用map存储
      
      */
      var twoSum = function (nums, target) {
        let map = new Map()
        for (let i = 0; i < nums.length; i++) {
          map.set(nums[i], i)
        }
        for (let i = 0; i < nums.length; i++) {
          let v = target - nums[i]
          if (map.has(v) && map.get(v) != i) {
            return [i, map.get(v)]
          }
        }
      }
    </script>
  </body>
</html>
